var app = getApp();
var util = require('../../utils/util.js')
//const homeData = require('../../antiqueData/antiqueData.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    phneUrl: '../../images/mine/phone.png',
    userInfo: {}
  },

  authorizePhone: function(){
    wx.navigateTo({
      url: "./authorizephone/authorizephone"
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })

    //var home = homeData.antiqueData;
    var mineDataUrl = app.globalData.antiqueBaseUrl + "queryTopicByOpenId.html";
    var openId = wx.getStorageSync('openid');
    util.httpMine(mineDataUrl, openId, this.initData);
  },

  initData: function(home){
    var homeAntique = [];
    var showThreeImg = [];
    home.forEach((antique)=>{
      var subject = antique.imgs.slice(0,3) 
      var threeImg = [];
      for (var i in subject){
        var item1 = subject[i];
        var item2 = app.globalData.antiqueImgUrl + item1;
        threeImg.push(item2);
      }
      var temp = {
        antiqueId: antique.id,
        publishTime: antique.times,
        antiqueName: antique.type.name,
        antiqueDesc: antique.content,
        browserNum: antique.views,
        showImg: threeImg
      }
      homeAntique.push(temp);
    })
    this.setData({
      homeAntique: homeAntique
    });
  },

  // 详情页面展示
  onAntiqueTap: function(event){
    var antiqueId = event.currentTarget.dataset.antiqueid;
    wx.navigateTo({
      url: "../detail/detail?id=" + antiqueId 
    })
  },
   
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})